package 设计mos.Prototype;

/**
 * @作者：xie
 * @时间：2022/10/10 19:01
 */
public class Main {
    public static void main(String[] args) {
        Product product1 = new Product(2, 2);
       System.out.println(product1.getId()+" "+product1.getPrice());

        Product product2 = (Product)product1.Clone();
        System.out.println(product2.getId()+" "+product2.getPrice());
    }
}

interface Prototype{
    public Object Clone();
}

class Product implements Prototype{

    private int id;
    private double price;

    public Product(){

    }

    public Product(int id,double price){
        this.id=id;
        this.price=price;
    }
    public int getId(){
        return id;
    }

    public double getPrice(){
        return price;
    }

    @Override
    public Object Clone() {
        Product object = new Product();
        object.id=this.id;
        object.price=this.price;
        return object;
    }
}
